import { observable, action } from 'mobx';
import { WeaTableNew } from 'comsMobx';

const { TableStore } = WeaTableNew;
import { WeaTools } from 'ecCom';
import { message } from 'antd';

import ListBaseStore from './ListBaseStore';
import Apis from '../apis/car';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
/**
 * 车辆编辑信息
 */
export default class CarInfoStore extends ListBaseStore {
  constructor() {
    super();
    this.title = getLabel(385851, '车辆基本信息');
    this.selectedKey = 'all';
  }

	  // 车辆类型数据
	  @observable typeList = {
	    carTypeListData: [],
	    status: '',
	  }

		@observable carinfoDatas = {};
		@observable isshare = 0;

  // 车辆保存提交
  saveorupdateCar = (params, func) => {
    Apis.saveorupdateCar(params).then((result) => {
      if (params && result && result.status === '1') {
        func(result);
        message.success(getLabel(385852, '保存车辆成功'));
      } else {
        message.error(getLabel(385853, '保存车辆失败'));
      }
    });
  }

  getCarInfo = (params, callbackfun) => {
    Apis.getCarInfo(params).then((result) => {
      if (params && result && result.status === '1') {
        callbackfun(result);
      } else {
        message.error(getLabel(385841, '获取车辆失败'));
      }
    });
  }

	initCarInfoForm=(params = {}, callback) => {
	  Apis.getCarFormField(params).then(
	    (result) => {
	      const { conditioninfo, isshare } = result;
	      this.conditioninfo = conditioninfo;
	      this.isshare = isshare;
	      this.initFormFields(conditioninfo); // 一定要先初始化initFormFields表单对象
	      if (callback) {
	        callback();
	      }
	    },
	  );
	}
}
